// pages/addinfo/addinfo.js
const request=require('../../util/request.js')
const instruct = require('../../util/tspl')
import bleDisNetwork from '../../util/bleDisNetwork'
Page({

  /**
   * 页面的初始数据
   */
  data: {
   
    list:[],
    page: 1,//页码
    limit: 5,//每页数量
    type:0,//可不传参数
    keyword:"",//可不传参数
    add_time:"",//可不传参数
    p_no:"",//项目号
    count: 0,
    flag: true,
    projectbody:[],//项目主体信息
    datastatus:2,//查看 2全部/1以完善/0未完成 
    datafind:"",//搜索单号
    codefind:"",//搜索单号
    date:"",
    mindate:Math.round((new Date() - 365*86400*1000)),
    findtime:"",//时间范围查找
    __returnParams:false,
    activeNames: [] // 当前展开的面板
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      __returnParams:false,

    })
    this.data.p_no = options.p_no
    this.data.page = 1
    this.getList()

  },
  
  getList(e) {
    var that = this;
    var params = {
      // page: that.data.page,//当前页码1
      // limit: that.data.limit,
      // keyword:that.data.datafind,//关键字
      // status:this.data.datastatus,
      // card:'',
      // note:'',
      // code:'',
      // cust_no:'',
      // product_name:'',
      no:'',
      add_time:this.data.findtime,
      no:this.data.datafind,
      code:this.data.codefind,
      product_name:'',
      status:that.data.datastatus,
    }
    //F251110010001-02
    console.log(params,"===params")
    request.requestAjax('fruit/get_check_log', params, "加载中",function (res) {
        console.log(res,"resssssssssss")
        // if (res.status === 200) {
        //   let list = that.data.list
        //   res.data.data.map((item) =>{
        //     return item.t = false;
        //   })
        //   if (that.data.page == 1) {
        //     list = []
        //   }
        //   list = [...list, ...res.data.data]
        //   if (list.length < res.data.count ){
        //     that.setData({
        //       page: that.data.page + 1,
        //       flag:true
        //     })
        //   } else {
        //     that.setData({
        //       flag:false
        //     })
        //   }
        //   that.setData({
        //     list: list,
        //     count: res.data.count
        //   })
        // }
        if(res.status === 200){
          that.setData({list:res.data.data})
        }
      }, function (res) {
        console.log(res,"请求失败")
      },
    )

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  submit(event){
  },
  bindKeyInputVant(event){
    let valueName = event.target.dataset.variable;
    let name = `formData.${valueName}`;
    this.setData({
      [valueName]:event.detail
    });
  },
  onTabChange(event){
    if(event.detail.index === 1){
      this.data.datastatus = 1
    }else if(event.detail.index === 2){
      this.data.datastatus = 0
    }else if(event.detail.index === 0){
      this.data.datastatus = 2
    }
    this.data.page = 1
    this.getList()
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 0
    })
  },
  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`;
  },
  onConfirm(event) {
    this.data.page = 1
    this.setData({
      show: false,
      date: this.formatDate(event.detail[0])+' - '+this.formatDate(event.detail[1]),
      findtime : this.formatDate(event.detail[0])+' - '+this.formatDate(event.detail[1])
    });
    this.getList("",this.data.date)
  },

  onSearch(e){
    this.setData({
      flag:true
    })
    this.data.page = 1
    this.data.datafind = e.detail
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 0
    })
    this.getList(e.detail)
  },
  onSearch_code(e){
    console.log(e,'saljidnsali')
    this.setData({
      flag:true
    })
    this.data.page = 1
    this.data.codefind = e.detail
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 0
    })
    this.getList(e.detail)
  },
  onReachBottom() {
    if(this.data.flag){
      this.setData({
        flag:false
      })
      this.getList(); // 疯狂的请求的方法
    }
  },
  comment(event){
    let tmp = event.currentTarget.dataset.index
    let pic_no = ""
    for(let i = 0;i<this.data.projectbody.length;i++){
      if(this.data.projectbody[i].id === tmp){
        pic_no = this.data.projectbody[i].pic_no
      }
    }
    wx.navigateTo({
      url: `/pages/pic_no_list_process/pic_no_list_process?p_no=${tmp}&pic_no=${pic_no}`,
    })
  },

  setrem(e){
    wx.navigateTo({
      url: `/pages/pic_no_rember/pic_no_rember?FInterID=${e.currentTarget.dataset.index}&fbillno=${e.currentTarget.dataset.fbillno}`,
    })
  },

  set_bao_gong(){
    wx.navigateTo({ url: '/pages/set_bao_gong/set_bao_gong' })
  },
  onCollapseChange(event) {
    this.setData({
      activeNames: event.detail
    });
  },

  set_bao_jian(){
    wx.navigateTo({ url: '/pages/set_bao_jian/set_bao_jian' })
  }
})